package com.cetc.stream;

import com.cetc.lambda.Person;
import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @Classname StreamTest04
 * @Description 排序测试
 * @Date 2023/1/17 13:08
 * @Created by louzhuangxi
 */
public class StreamTest04 {
    List<Person> personList = Arrays.asList(
            new Person("张三", 24),
            new Person("李四", 80),
            new Person("王五", 28),
            new Person("赵六2", 42),
            new Person("赵六1", 42),
            new Person("田七", 28)
    );
    @Test
    public void test02() {
        //自然排序，从小到大
        System.out.println("****************************自然排序，从小到大**********************************");
        personList.stream().map(Person::getAge).sorted().forEach(System.out::println);
        //比较器排序，自定义
        System.out.println("****************************比较器排序，自定义**********************************");
        personList.stream().sorted(Comparator.comparing(Person::getAge).reversed()).map(Person::getAge).forEach(System.out::println);
    }
}
